package com.mofeng.myshop.controller.admin;


import com.mofeng.myshop.domain.dto.ProjectDto;
import com.mofeng.myshop.service.IProjectService;
import com.mofeng.myshop.until.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 项目 前端控制器
 * </p>
 *
 * @author MoFeng
 * @since 2024-04-15
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/project")
@Tag(name = "项目相关接口", description = "项目相关接口")
@PreAuthorize(value = "@permissionService.NORMAL()")
public class ProjectAdminController {

    private final IProjectService projectService;

    @Operation(summary = "获取项目列表")
    @GetMapping("/list")
    public R getListAdmin() {
        return projectService.getListAdmin();
    }

    @Operation(summary = "添加项目")
    @PostMapping("")
    @PreAuthorize(value = "@permissionService.MASTER()")
    public R addProject(@RequestBody ProjectDto projectDto) {
        return projectService.saveProject(projectDto);
    }

    @Operation(summary = "修改项目")
    @PutMapping("")
    @PreAuthorize(value = "@permissionService.MASTER()")
    public R updateProject(@RequestBody ProjectDto projectDto) {
        return projectService.saveProject(projectDto);
    }

    @Operation(summary = "删除项目")
    @DeleteMapping()
    @PreAuthorize(value = "@permissionService.MASTER()")
    public R deleteProject(@RequestParam("id") List<String> ids) {
        return projectService.deleteProject(ids);
    }
}
